using System;
using System.Collections.Generic;

namespace Vibstudio.X4NET.IO.INI.Model
{
    public class SectionData : ICloneable
    {
        #region Initialization

        public SectionData(string sectionName)
        {
            if (string.IsNullOrEmpty(sectionName)) throw new ArgumentException("section name can not be empty");

            _leadingComments = new List<string>();
            _keyDataCollection = new KeyDataCollection();
            SectionName = sectionName;
        }

        public SectionData(SectionData ori)
        {
            _leadingComments = new List<string>(ori._leadingComments);
            _keyDataCollection = new KeyDataCollection(ori._keyDataCollection);
        }

        #endregion

		#region Operations
		
        public void ClearKeyData()
		{
			_keyDataCollection.RemoveAllKeys();
		}
		
        #endregion

        #region Properties

        public string SectionName
        {
            get
            {
                return _sectionName;
            }

            set
            {
                if (!string.IsNullOrEmpty(value))
                    _sectionName = value;
            }
        }

        public List<string> LeadingComments
        {
            get
            {
                return _leadingComments;
            }

            internal set
            {
                _leadingComments = new List<string>(value);
            }
        }

        public List<string> Comments
        {
            get
            {
                var list = new List<string>(_leadingComments);
                list.AddRange(_trailingComments);
                return list;
            }
        }

        public List<string> TrailingComments
        {
            get
            {
                return _trailingComments;
            }

            internal set
            {
                _trailingComments = new List<string>(value);
            }
        }
        
        public KeyDataCollection Keys
        {
            get
            {
                return _keyDataCollection;
            }

            set
            {
                _keyDataCollection = value;
            }
        }

        #endregion

        #region ICloneable Members

        public object Clone()
        {
            return new SectionData(this);
        }

        #endregion

        #region Non-public members

        private List<string> _leadingComments;
        private List<string> _trailingComments = new List<string>();
        private KeyDataCollection _keyDataCollection;
        private string _sectionName;
        
        #endregion
    }
}